#ifndef _SOCKETNOTIFIER_HPP_
#define _SOCKETNOTIFIER_HPP_

#include "jhdefs.hpp"
#include "net/Socket.hpp"
#include "net/SocketNotification.hpp"
#include "net/SocketReactor.hpp"
#include "msg/abstractobserver.hpp"
#include "msg/notificationcenter.hpp"
using JHCPP::msg::CAbstractObserver;
using JHCPP::msg::CNotificationCenter;
#include "thread/atomiccounter.hpp"
#include <set>

NET_NAMESPACE_BEGIN

class CSocketNotifier : public CRefCountedObject
{
public:
	explicit CSocketNotifier(const CSocket& socket);

	void addObserver(CSocketReactor* pReactor, const CAbstractObserver& observer);
	void removeObserver(CSocketReactor* pReactor, const CAbstractObserver& observer);
	bool hasObserver(const CAbstractObserver& observer) const;
	bool accepts(CSocketNotification* pNotification);
	void dispatch(CSocketNotification* pNotification);
	bool hasObservers() const;
	std::size_t countObservers() const;

protected:
	~CSocketNotifier();

private:
	typedef std::multiset<CSocketNotification*> EventSet;

	EventSet			m_events;
	CNotificationCenter	m_nc;
	CSocket				m_socket;
};

NET_NAMESPACE_END

#endif
